package com.efast.dmom.mes.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.bean.TreeQuery;
import com.efast.dmom.mes.service.ProductionLineService;
import com.efast.dmom.mes.service.WorkCenterService;
import com.efast.dmom.mes.service.WorkShopService;

@Controller
@RequestMapping("/plantTree")
public class PlantTreeController {
	@Autowired
	private WorkShopService workShopService;
	@Autowired
	ProductionLineService productionLineService;
	@Autowired
	WorkCenterService workCenterService;
	@RequestMapping(value = "/query")
	public @ResponseBody ResultBean query(@RequestBody TreeQuery treeQuery) {
		ResultBean resultBean = new ResultBean(true, ' ');
		String flag = treeQuery.getFlag();
		long id = treeQuery.getId();
		
		if (flag.equals("com.efast.dmom.mes.bean.Plant")) {
			return workShopService.getWorkshopsByPlantId(id);

		} else if (flag.equals("com.efast.dmom.mes.bean.Workshop")) {
			resultBean = productionLineService.getByWorkshopId(id);
	
		} else if (flag.equals("com.efast.dmom.mes.bean.ProductionLine")) {
			resultBean = workCenterService.getByLineId(id);
		}
		else if (flag.equals("com.efast.dmom.mes.bean.WorkCenter")) {
			resultBean.setObject(null);
		}else {
			resultBean.setObject(null);
		}
		return resultBean;
	}
}
